﻿using System;
using System.Linq;
//using Zj.HttpCodeDemo.ConsoleApp.CodeFirst;
//using Zj.HttpCodeDemo.ConsoleApp.CodeFirst.Core;
using Zj.HttpCodeDemo.Repository.Models;
using Zj.HttpCodeDemo.Domain.Core;

namespace Zj.HttpCodeDemo.ConsoleApp.Samples
{
    internal class EntityFrameworkCodeFirstSample
    {
        //internal static void Sample()
        //{
        //    using (var ctx = new CodeFirstTestDbContext())
        //    {
        //        //SeedData(ctx);
        //        ctx.UserLoginErrLog
        //           .ToList()
        //           .ForEach(log => Console.WriteLine($"{log.User.UserName},\t于{log.LoginTime},\t使用{log.IPAddress}\t登录"));
        //    }
        //}

        //private static void SeedData(CodeFirstTestDbContext ctx)
        //{
        //    //var log = new UserLoginErrLog()
        //    //{
        //    //    IPAddress = "192.168.9.14",
        //    //    LoginTime = DateTime.UtcNow,
        //    //};
        //    //log.User = new User() { UserName = "Super", Password = "p@ssw0rd", Age = 24 };
        //    var log = new UserLoginErrLog()
        //    {
        //        IPAddress = "192.168.9.10",
        //        LoginTime = DateTime.UtcNow,
        //        User = new User() { UserName = "admin", Password = "p@ssw0rd", Age = 24 }
        //    };

        //    ctx.UserLoginErrLog.Add(log);
        //    ctx.SaveChanges();
        //}

        internal static void Sample2()
        {
            using (var ctx = new TodoDbContext())
            {
                //SeedData2(ctx);
                //ctx.User
                //   .ToList()
                //   .ForEach(u => Console.WriteLine($"账号:{u.UserName},\t密码:{u.Password},\t部门:{u.Department.Name},\t真实姓名:{u.UserInfo.RealName}\t"));

                //var department = ctx.Department
                //    .First();
                //var list = department
                //    .Users
                //    .ToList();

                //list.ForEach(u => Console.WriteLine($"账号:{u.UserName},\t密码:{u.Password},\t部门:{u.Department.Name},\t真实姓名:{u.UserInfo.RealName}\t"));

            }
        }

        //private static void SeedData2(TodoDbContext ctx)
        //{
        //    var user = new User()
        //    {
        //        UserName = "super",
        //        Password = "p@ssw0rd"
        //    };
        //    user.Department = new Department()
        //    {
        //        Name = "技术研发部",
        //        CreateDate = DateTime.Now,
        //    };
        //    user.UserInfo = new UserInfo()
        //    {
        //        Age = 25,
        //        RealName = "Super",
        //        Address = "江苏省南京市栖霞区"
        //    };
        //    ctx.User.Add(user);
        //    ctx.SaveChanges();

        //    var admin = new User()
        //    {
        //        UserName = "admin",
        //        Password = "p@ssw0rd",
        //        DepartmentId = ctx.Department.First().Id,
        //    };
        //    admin.UserInfo = new UserInfo()
        //    {
        //        Age = 26,
        //        RealName = "admin",
        //        Address = "江苏省南京市栖霞区"
        //    };
        //    ctx.User.Add(admin);


        //    var @operator = new User()
        //    {
        //        UserName = "operator",
        //        Password = "p@ssw0rd",
        //        DepartmentId = ctx.Department.First().Id,
        //    };
        //    //@operator.UserInfo = new UserInfo()
        //    //{
        //    //    Age = 27,
        //    //    RealName = "operator",
        //    //    Address = "江苏省南京市栖霞区"
        //    //};
        //    ctx.User.Add(@operator);
        //    ctx.SaveChanges();
        //}
    }
}